package com.zyb.service.impl;



import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;


import org.springframework.stereotype.Service;

import com.zyb.dao.MessageDao;
import com.zyb.pojo.Message;
import com.zyb.pojo.User;
import com.zyb.service.MessageService;

@Service("MessageService")
public class MessageServiceImpl implements MessageService {

	@Resource
	private MessageDao mdao;
	private String result;
	
	@Override
	public String insertMessage(String msg,User user) {
		try {
		Message message = new Message();
		message.setUser_id(user.getId());
		message.setMessage(msg);
		message.setName(user.getName());
		
		Date date = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String time = formatter.format(date);
		message.setDate(time);
		
			mdao.insertMessage(message);
			result = "留言成功";
			return result;
		}catch (Exception e) {
			e.printStackTrace();
			result = "留言失败";
			return result;
		}
		
	}

	@Override
	public List<Message> findMessages() {
		
		return mdao.findMessages();
	}

}
